
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, 2012 and Azure
-- --------------------------------------------------
-- Date Created: 09/19/2014 09:56:02
-- Generated from EDMX file: C:\Users\edneysilva\Particular\TC2\RZ Corporativo\RzCorporativo.DataAccess\CurriculoEntity.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [SistemaCurricular];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[FK_Cargo_AreaConhecimento]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Cargo] DROP CONSTRAINT [FK_Cargo_AreaConhecimento];
GO
IF OBJECT_ID(N'[dbo].[FK_CargoPretendido_Cargo]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[CargoPretendido] DROP CONSTRAINT [FK_CargoPretendido_Cargo];
GO
IF OBJECT_ID(N'[dbo].[FK_CargoPretendido_Curriculo]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[CargoPretendido] DROP CONSTRAINT [FK_CargoPretendido_Curriculo];
GO
IF OBJECT_ID(N'[dbo].[FK_Certificado_Cidade]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Certificado] DROP CONSTRAINT [FK_Certificado_Cidade];
GO
IF OBJECT_ID(N'[dbo].[FK_Curriculo_Usuario]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Curriculo] DROP CONSTRAINT [FK_Curriculo_Usuario];
GO
IF OBJECT_ID(N'[dbo].[FK_Curso_AreaConhecimento]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Curso] DROP CONSTRAINT [FK_Curso_AreaConhecimento];
GO
IF OBJECT_ID(N'[dbo].[FK_Empresa_Cidade]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Empresa] DROP CONSTRAINT [FK_Empresa_Cidade];
GO
IF OBJECT_ID(N'[dbo].[FK_Endereco_Cidade1]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Endereco] DROP CONSTRAINT [FK_Endereco_Cidade1];
GO
IF OBJECT_ID(N'[dbo].[FK_Experiencia_Cargo]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Experiencia] DROP CONSTRAINT [FK_Experiencia_Cargo];
GO
IF OBJECT_ID(N'[dbo].[FK_Experiencia_Curriculo]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Experiencia] DROP CONSTRAINT [FK_Experiencia_Curriculo];
GO
IF OBJECT_ID(N'[dbo].[FK_Feedback_Usuario]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Feedback] DROP CONSTRAINT [FK_Feedback_Usuario];
GO
IF OBJECT_ID(N'[dbo].[FK_Feedback_Usuario1]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Feedback] DROP CONSTRAINT [FK_Feedback_Usuario1];
GO
IF OBJECT_ID(N'[dbo].[FK_Feedback_Vaga]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Feedback] DROP CONSTRAINT [FK_Feedback_Vaga];
GO
IF OBJECT_ID(N'[dbo].[FK_Formacao_Curso]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Formacao] DROP CONSTRAINT [FK_Formacao_Curso];
GO
IF OBJECT_ID(N'[dbo].[FK_Formacao_Formacao]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Formacao] DROP CONSTRAINT [FK_Formacao_Formacao];
GO
IF OBJECT_ID(N'[dbo].[FK_Formacao_Usuario]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Formacao] DROP CONSTRAINT [FK_Formacao_Usuario];
GO
IF OBJECT_ID(N'[dbo].[FK_FormacaoVaga_FormacaoVaga]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[FormacaoVaga] DROP CONSTRAINT [FK_FormacaoVaga_FormacaoVaga];
GO
IF OBJECT_ID(N'[dbo].[FK_FormacaoVaga_Vaga]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[FormacaoVaga] DROP CONSTRAINT [FK_FormacaoVaga_Vaga];
GO
IF OBJECT_ID(N'[dbo].[FK_HabilidadesUsuario_ItemAreaConhecimento]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[HabilidadesUsuario] DROP CONSTRAINT [FK_HabilidadesUsuario_ItemAreaConhecimento];
GO
IF OBJECT_ID(N'[dbo].[FK_HabilidadesUsuario_Usuario]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[HabilidadesUsuario] DROP CONSTRAINT [FK_HabilidadesUsuario_Usuario];
GO
IF OBJECT_ID(N'[dbo].[FK_HistoricoIndicacoes_Usuario]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[HistoricoIndicacoes] DROP CONSTRAINT [FK_HistoricoIndicacoes_Usuario];
GO
IF OBJECT_ID(N'[dbo].[FK_IdiomaUsuario_ItemAreaConhecimento]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[IdiomaUsuario] DROP CONSTRAINT [FK_IdiomaUsuario_ItemAreaConhecimento];
GO
IF OBJECT_ID(N'[dbo].[FK_IdiomaUsuario_Usuario]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[IdiomaUsuario] DROP CONSTRAINT [FK_IdiomaUsuario_Usuario];
GO
IF OBJECT_ID(N'[dbo].[FK_IdiomaVaga_Idioma]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[IdiomaVaga] DROP CONSTRAINT [FK_IdiomaVaga_Idioma];
GO
IF OBJECT_ID(N'[dbo].[FK_IdiomaVaga_Vaga]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[IdiomaVaga] DROP CONSTRAINT [FK_IdiomaVaga_Vaga];
GO
IF OBJECT_ID(N'[dbo].[FK_Indicacao_Usuario]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Indicacao] DROP CONSTRAINT [FK_Indicacao_Usuario];
GO
IF OBJECT_ID(N'[dbo].[FK_Indicacao_Usuario_Indicador]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Indicacao] DROP CONSTRAINT [FK_Indicacao_Usuario_Indicador];
GO
IF OBJECT_ID(N'[dbo].[FK_Indicacao_Vaga]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Indicacao] DROP CONSTRAINT [FK_Indicacao_Vaga];
GO
IF OBJECT_ID(N'[dbo].[FK_ItemAreaConhecimento_AreaConhecimento]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[ItemAreaConhecimento] DROP CONSTRAINT [FK_ItemAreaConhecimento_AreaConhecimento];
GO
IF OBJECT_ID(N'[dbo].[FK_ItemGrupo_Grupo]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[ItemGrupo] DROP CONSTRAINT [FK_ItemGrupo_Grupo];
GO
IF OBJECT_ID(N'[dbo].[FK_ItemGrupo_ItemSistema]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[ItemGrupo] DROP CONSTRAINT [FK_ItemGrupo_ItemSistema];
GO
IF OBJECT_ID(N'[dbo].[FK_ItemSistema_TipoItem]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[ItemSistema] DROP CONSTRAINT [FK_ItemSistema_TipoItem];
GO
IF OBJECT_ID(N'[dbo].[FK_LoginGrupo_Grupo]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[LoginGrupo] DROP CONSTRAINT [FK_LoginGrupo_Grupo];
GO
IF OBJECT_ID(N'[dbo].[FK_LoginGrupo_LOGIN]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[LoginGrupo] DROP CONSTRAINT [FK_LoginGrupo_LOGIN];
GO
IF OBJECT_ID(N'[dbo].[FK_Notificacao_Login]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Notificacao] DROP CONSTRAINT [FK_Notificacao_Login];
GO
IF OBJECT_ID(N'[dbo].[FK_Permissoes_ItemSistema]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Permissoes] DROP CONSTRAINT [FK_Permissoes_ItemSistema];
GO
IF OBJECT_ID(N'[dbo].[FK_Permissoes_Usuario]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Permissoes] DROP CONSTRAINT [FK_Permissoes_Usuario];
GO
IF OBJECT_ID(N'[dbo].[FK_Usuario_Endereco]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Usuario] DROP CONSTRAINT [FK_Usuario_Endereco];
GO
IF OBJECT_ID(N'[dbo].[FK_Usuario_Login]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Usuario] DROP CONSTRAINT [FK_Usuario_Login];
GO
IF OBJECT_ID(N'[dbo].[FK_USUARIO_REPRESENTANTE]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Empresa] DROP CONSTRAINT [FK_USUARIO_REPRESENTANTE];
GO
IF OBJECT_ID(N'[dbo].[FK_Vaga_Cargo]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Vaga] DROP CONSTRAINT [FK_Vaga_Cargo];
GO
IF OBJECT_ID(N'[dbo].[FK_Vaga_Usuario]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Vaga] DROP CONSTRAINT [FK_Vaga_Usuario];
GO

-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[AreaConhecimento]', 'U') IS NOT NULL
    DROP TABLE [dbo].[AreaConhecimento];
GO
IF OBJECT_ID(N'[dbo].[Cargo]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Cargo];
GO
IF OBJECT_ID(N'[dbo].[CargoPretendido]', 'U') IS NOT NULL
    DROP TABLE [dbo].[CargoPretendido];
GO
IF OBJECT_ID(N'[dbo].[Certificado]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Certificado];
GO
IF OBJECT_ID(N'[dbo].[Cidade]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Cidade];
GO
IF OBJECT_ID(N'[dbo].[Curriculo]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Curriculo];
GO
IF OBJECT_ID(N'[dbo].[Curso]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Curso];
GO
IF OBJECT_ID(N'[dbo].[Empresa]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Empresa];
GO
IF OBJECT_ID(N'[dbo].[Endereco]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Endereco];
GO
IF OBJECT_ID(N'[dbo].[Experiencia]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Experiencia];
GO
IF OBJECT_ID(N'[dbo].[Feedback]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Feedback];
GO
IF OBJECT_ID(N'[dbo].[Formacao]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Formacao];
GO
IF OBJECT_ID(N'[dbo].[FormacaoVaga]', 'U') IS NOT NULL
    DROP TABLE [dbo].[FormacaoVaga];
GO
IF OBJECT_ID(N'[dbo].[Grupo]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Grupo];
GO
IF OBJECT_ID(N'[dbo].[HabilidadesUsuario]', 'U') IS NOT NULL
    DROP TABLE [dbo].[HabilidadesUsuario];
GO
IF OBJECT_ID(N'[dbo].[HistoricoIndicacoes]', 'U') IS NOT NULL
    DROP TABLE [dbo].[HistoricoIndicacoes];
GO
IF OBJECT_ID(N'[dbo].[Idioma]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Idioma];
GO
IF OBJECT_ID(N'[dbo].[IdiomaUsuario]', 'U') IS NOT NULL
    DROP TABLE [dbo].[IdiomaUsuario];
GO
IF OBJECT_ID(N'[dbo].[IdiomaVaga]', 'U') IS NOT NULL
    DROP TABLE [dbo].[IdiomaVaga];
GO
IF OBJECT_ID(N'[dbo].[Indicacao]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Indicacao];
GO
IF OBJECT_ID(N'[dbo].[ItemAreaConhecimento]', 'U') IS NOT NULL
    DROP TABLE [dbo].[ItemAreaConhecimento];
GO
IF OBJECT_ID(N'[dbo].[ItemGrupo]', 'U') IS NOT NULL
    DROP TABLE [dbo].[ItemGrupo];
GO
IF OBJECT_ID(N'[dbo].[ItemSistema]', 'U') IS NOT NULL
    DROP TABLE [dbo].[ItemSistema];
GO
IF OBJECT_ID(N'[dbo].[Login]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Login];
GO
IF OBJECT_ID(N'[dbo].[LoginGrupo]', 'U') IS NOT NULL
    DROP TABLE [dbo].[LoginGrupo];
GO
IF OBJECT_ID(N'[dbo].[Notificacao]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Notificacao];
GO
IF OBJECT_ID(N'[dbo].[Permissoes]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Permissoes];
GO
IF OBJECT_ID(N'[dbo].[TipoItem]', 'U') IS NOT NULL
    DROP TABLE [dbo].[TipoItem];
GO
IF OBJECT_ID(N'[dbo].[Usuario]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Usuario];
GO
IF OBJECT_ID(N'[dbo].[Vaga]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Vaga];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'AreaConhecimento'
CREATE TABLE [dbo].[AreaConhecimento] (
    [AreaId] int IDENTITY(1,1) NOT NULL,
    [Nome] varchar(30)  NOT NULL,
    [Ativo] bit  NOT NULL
);
GO

-- Creating table 'Cargo'
CREATE TABLE [dbo].[Cargo] (
    [CargoId] int IDENTITY(1,1) NOT NULL,
    [Nome] varchar(50)  NOT NULL,
    [AreaId] int  NOT NULL
);
GO

-- Creating table 'Certificado'
CREATE TABLE [dbo].[Certificado] (
    [CertificadoId] int IDENTITY(1,1) NOT NULL,
    [Descricao] varchar(20)  NOT NULL,
    [Instituicao] varchar(50)  NOT NULL,
    [Ano] smallint  NOT NULL,
    [CidadeId] int  NOT NULL
);
GO

-- Creating table 'Cidade'
CREATE TABLE [dbo].[Cidade] (
    [CidadeId] int IDENTITY(1,1) NOT NULL,
    [Nome] varchar(30)  NOT NULL,
    [UF] varchar(3)  NOT NULL
);
GO

-- Creating table 'Curriculo'
CREATE TABLE [dbo].[Curriculo] (
    [CurriculoId] bigint IDENTITY(1,1) NOT NULL,
    [UsuarioId] bigint  NOT NULL,
    [DataCadastro] datetime  NOT NULL,
    [PretencaoSalarial] decimal(19,4)  NOT NULL,
    [DisponibilidadeHorario] smallint  NOT NULL
);
GO

-- Creating table 'Curso'
CREATE TABLE [dbo].[Curso] (
    [CursoId] int IDENTITY(1,1) NOT NULL,
    [Nome] varchar(30)  NOT NULL,
    [Ativo] bit  NOT NULL,
    [AreaId] int  NOT NULL
);
GO

-- Creating table 'Empresa'
CREATE TABLE [dbo].[Empresa] (
    [EmpresaId] int IDENTITY(1,1) NOT NULL,
    [Nome] varchar(30)  NOT NULL,
    [UsuarioRepresentanteId] bigint  NOT NULL,
    [Ativo] bit  NOT NULL,
    [CidadeId] int  NOT NULL,
    [Endereco] varchar(50)  NOT NULL
);
GO

-- Creating table 'Endereco'
CREATE TABLE [dbo].[Endereco] (
    [EnderecoId] int IDENTITY(1,1) NOT NULL,
    [CidadeId] int  NOT NULL,
    [Cep] varchar(10)  NOT NULL,
    [Logradouro] varchar(30)  NULL,
    [Numero] varchar(10)  NULL
);
GO

-- Creating table 'Experiencia'
CREATE TABLE [dbo].[Experiencia] (
    [ExperienciaId] bigint IDENTITY(1,1) NOT NULL,
    [CurriculoId] bigint  NOT NULL,
    [Empresa] varchar(50)  NOT NULL,
    [CargoId] int  NOT NULL,
    [Atividades] varchar(3000)  NULL,
    [DataAdminissao] datetime  NOT NULL,
    [DataDemissao] datetime  NULL,
    [EmpregoAtual] bit  NOT NULL,
    [NomeContato] varchar(50)  NULL,
    [TelefoneEmpresa] varchar(15)  NULL
);
GO

-- Creating table 'Feedback'
CREATE TABLE [dbo].[Feedback] (
    [VagaId] bigint  NOT NULL,
    [UsuarioIndicadoId] bigint  NOT NULL,
    [Comentario] varchar(8000)  NOT NULL,
    [UsarioPostId] bigint  NOT NULL,
    [DataPostagem] datetime  NOT NULL
);
GO

-- Creating table 'Formacao'
CREATE TABLE [dbo].[Formacao] (
    [FormacaoId] bigint IDENTITY(1,1) NOT NULL,
    [Instituicao] varchar(50)  NOT NULL,
    [AnoInicio] int  NOT NULL,
    [AnoFim] int  NOT NULL,
    [Concluido] bit  NOT NULL,
    [CursoId] int  NOT NULL,
    [EnderecoId] int  NOT NULL,
    [UsuarioId] bigint  NOT NULL
);
GO

-- Creating table 'Grupo'
CREATE TABLE [dbo].[Grupo] (
    [GrupoId] int IDENTITY(1,1) NOT NULL,
    [Descricao] varchar(100)  NOT NULL,
    [Ativo] bit  NOT NULL
);
GO

-- Creating table 'HistoricoIndicacoes'
CREATE TABLE [dbo].[HistoricoIndicacoes] (
    [VagaId] bigint  NOT NULL,
    [UsuarioIndicadoId] bigint  NOT NULL,
    [DataPostagem] datetime  NOT NULL,
    [Comentario] varchar(8000)  NOT NULL,
    [UsuarioPublicadorId] bigint  NOT NULL,
    [Status] smallint  NOT NULL
);
GO

-- Creating table 'Idioma'
CREATE TABLE [dbo].[Idioma] (
    [IdiomaId] int IDENTITY(1,1) NOT NULL,
    [Nome] varchar(50)  NOT NULL
);
GO

-- Creating table 'IdiomaUsuario'
CREATE TABLE [dbo].[IdiomaUsuario] (
    [UsuarioId] bigint  NOT NULL,
    [IdiomaId] int  NOT NULL,
    [Nivel] char(1)  NOT NULL
);
GO

-- Creating table 'IdiomaVaga'
CREATE TABLE [dbo].[IdiomaVaga] (
    [IdiomaId] int  NOT NULL,
    [VagaId] bigint  NOT NULL,
    [Nivel] char(1)  NOT NULL
);
GO

-- Creating table 'Indicacao'
CREATE TABLE [dbo].[Indicacao] (
    [VagaId] bigint  NOT NULL,
    [UsuarioIndicadoId] bigint  NOT NULL,
    [DataIndicacao] datetime  NOT NULL,
    [Status] smallint  NOT NULL,
    [ResultadoFinal] smallint  NOT NULL,
    [UsuarioIndicadorId] bigint  NOT NULL
);
GO

-- Creating table 'ItemAreaConhecimento'
CREATE TABLE [dbo].[ItemAreaConhecimento] (
    [ItemId] int IDENTITY(1,1) NOT NULL,
    [Descricao] varchar(50)  NOT NULL,
    [Ativo] bit  NOT NULL,
    [AreaConhecimentoId] int  NOT NULL
);
GO

-- Creating table 'ItemGrupo'
CREATE TABLE [dbo].[ItemGrupo] (
    [GrupoItemId] bigint  NOT NULL,
    [GrupoId] int  NOT NULL,
    [ItemId] bigint  NOT NULL
);
GO

-- Creating table 'ItemSistema'
CREATE TABLE [dbo].[ItemSistema] (
    [ItemId] bigint IDENTITY(1,1) NOT NULL,
    [Nome] varchar(100)  NOT NULL,
    [Url] varchar(1000)  NOT NULL,
    [Ativo] bit  NOT NULL,
    [ItemPaiId] bigint  NULL,
    [TipoItemId] int  NOT NULL
);
GO

-- Creating table 'Login'
CREATE TABLE [dbo].[Login] (
    [LoginId] int IDENTITY(1,1) NOT NULL,
    [Nick] varchar(50)  NOT NULL,
    [Senha] varchar(200)  NOT NULL,
    [Ativo] bit  NOT NULL,
    [TipoLogin] smallint  NOT NULL
);
GO

-- Creating table 'Notificacao'
CREATE TABLE [dbo].[Notificacao] (
    [LoginId] int  NOT NULL,
    [Data] datetime  NOT NULL,
    [Titulo] varchar(50)  NULL,
    [TipoNotificacao] nchar(10)  NOT NULL,
    [Mensagem] varchar(8000)  NOT NULL,
    [Visualizado] bit  NOT NULL
);
GO

-- Creating table 'Permissoes'
CREATE TABLE [dbo].[Permissoes] (
    [ItemId] bigint  NOT NULL,
    [UsuarioId] bigint  NOT NULL,
    [Ativo] bit  NOT NULL
);
GO

-- Creating table 'TipoItem'
CREATE TABLE [dbo].[TipoItem] (
    [TipoItemId] int IDENTITY(1,1) NOT NULL,
    [Descricao] varchar(100)  NOT NULL
);
GO

-- Creating table 'Usuario'
CREATE TABLE [dbo].[Usuario] (
    [UsuarioId] bigint IDENTITY(1,1) NOT NULL,
    [Nome] varchar(50)  NOT NULL,
    [DataNasc] datetime  NOT NULL,
    [Cpf] varchar(15)  NOT NULL,
    [Email] varchar(50)  NOT NULL,
    [Ativo] bit  NOT NULL,
    [Telefone] varchar(14)  NOT NULL,
    [Sexo] char(1)  NOT NULL,
    [LoginId] int  NOT NULL,
    [EnderecoId] int  NOT NULL
);
GO

-- Creating table 'Vaga'
CREATE TABLE [dbo].[Vaga] (
    [VagaId] bigint IDENTITY(1,1) NOT NULL,
    [CargoId] int  NOT NULL,
    [Ativo] bit  NOT NULL,
    [SalarioOfertado] decimal(19,4)  NULL,
    [Disponibilidade] smallint  NOT NULL,
    [DataCadastro] datetime  NOT NULL,
    [QtdVagas] smallint  NOT NULL,
    [Status] smallint  NOT NULL,
    [UsuarioRepresentanteId] bigint  NOT NULL,
    [Observacoes] varchar(5000)  NULL
);
GO

-- Creating table 'CargoPretendido'
CREATE TABLE [dbo].[CargoPretendido] (
    [Cargo_CargoId] int  NOT NULL,
    [Curriculo_CurriculoId] bigint  NOT NULL
);
GO

-- Creating table 'FormacaoVaga'
CREATE TABLE [dbo].[FormacaoVaga] (
    [Curso_CursoId] int  NOT NULL,
    [Vaga_VagaId] bigint  NOT NULL
);
GO

-- Creating table 'HabilidadesUsuario'
CREATE TABLE [dbo].[HabilidadesUsuario] (
    [ItemAreaConhecimento_ItemId] int  NOT NULL,
    [Usuario_UsuarioId] bigint  NOT NULL
);
GO

-- Creating table 'LoginGrupo'
CREATE TABLE [dbo].[LoginGrupo] (
    [Grupo_GrupoId] int  NOT NULL,
    [Login_LoginId] int  NOT NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [AreaId] in table 'AreaConhecimento'
ALTER TABLE [dbo].[AreaConhecimento]
ADD CONSTRAINT [PK_AreaConhecimento]
    PRIMARY KEY CLUSTERED ([AreaId] ASC);
GO

-- Creating primary key on [CargoId] in table 'Cargo'
ALTER TABLE [dbo].[Cargo]
ADD CONSTRAINT [PK_Cargo]
    PRIMARY KEY CLUSTERED ([CargoId] ASC);
GO

-- Creating primary key on [CertificadoId] in table 'Certificado'
ALTER TABLE [dbo].[Certificado]
ADD CONSTRAINT [PK_Certificado]
    PRIMARY KEY CLUSTERED ([CertificadoId] ASC);
GO

-- Creating primary key on [CidadeId] in table 'Cidade'
ALTER TABLE [dbo].[Cidade]
ADD CONSTRAINT [PK_Cidade]
    PRIMARY KEY CLUSTERED ([CidadeId] ASC);
GO

-- Creating primary key on [CurriculoId] in table 'Curriculo'
ALTER TABLE [dbo].[Curriculo]
ADD CONSTRAINT [PK_Curriculo]
    PRIMARY KEY CLUSTERED ([CurriculoId] ASC);
GO

-- Creating primary key on [CursoId] in table 'Curso'
ALTER TABLE [dbo].[Curso]
ADD CONSTRAINT [PK_Curso]
    PRIMARY KEY CLUSTERED ([CursoId] ASC);
GO

-- Creating primary key on [EmpresaId] in table 'Empresa'
ALTER TABLE [dbo].[Empresa]
ADD CONSTRAINT [PK_Empresa]
    PRIMARY KEY CLUSTERED ([EmpresaId] ASC);
GO

-- Creating primary key on [EnderecoId] in table 'Endereco'
ALTER TABLE [dbo].[Endereco]
ADD CONSTRAINT [PK_Endereco]
    PRIMARY KEY CLUSTERED ([EnderecoId] ASC);
GO

-- Creating primary key on [ExperienciaId] in table 'Experiencia'
ALTER TABLE [dbo].[Experiencia]
ADD CONSTRAINT [PK_Experiencia]
    PRIMARY KEY CLUSTERED ([ExperienciaId] ASC);
GO

-- Creating primary key on [VagaId], [UsuarioIndicadoId], [DataPostagem] in table 'Feedback'
ALTER TABLE [dbo].[Feedback]
ADD CONSTRAINT [PK_Feedback]
    PRIMARY KEY CLUSTERED ([VagaId], [UsuarioIndicadoId], [DataPostagem] ASC);
GO

-- Creating primary key on [FormacaoId] in table 'Formacao'
ALTER TABLE [dbo].[Formacao]
ADD CONSTRAINT [PK_Formacao]
    PRIMARY KEY CLUSTERED ([FormacaoId] ASC);
GO

-- Creating primary key on [GrupoId] in table 'Grupo'
ALTER TABLE [dbo].[Grupo]
ADD CONSTRAINT [PK_Grupo]
    PRIMARY KEY CLUSTERED ([GrupoId] ASC);
GO

-- Creating primary key on [VagaId], [UsuarioIndicadoId], [DataPostagem] in table 'HistoricoIndicacoes'
ALTER TABLE [dbo].[HistoricoIndicacoes]
ADD CONSTRAINT [PK_HistoricoIndicacoes]
    PRIMARY KEY CLUSTERED ([VagaId], [UsuarioIndicadoId], [DataPostagem] ASC);
GO

-- Creating primary key on [IdiomaId] in table 'Idioma'
ALTER TABLE [dbo].[Idioma]
ADD CONSTRAINT [PK_Idioma]
    PRIMARY KEY CLUSTERED ([IdiomaId] ASC);
GO

-- Creating primary key on [UsuarioId], [IdiomaId] in table 'IdiomaUsuario'
ALTER TABLE [dbo].[IdiomaUsuario]
ADD CONSTRAINT [PK_IdiomaUsuario]
    PRIMARY KEY CLUSTERED ([UsuarioId], [IdiomaId] ASC);
GO

-- Creating primary key on [IdiomaId], [VagaId] in table 'IdiomaVaga'
ALTER TABLE [dbo].[IdiomaVaga]
ADD CONSTRAINT [PK_IdiomaVaga]
    PRIMARY KEY CLUSTERED ([IdiomaId], [VagaId] ASC);
GO

-- Creating primary key on [VagaId], [UsuarioIndicadoId], [DataIndicacao] in table 'Indicacao'
ALTER TABLE [dbo].[Indicacao]
ADD CONSTRAINT [PK_Indicacao]
    PRIMARY KEY CLUSTERED ([VagaId], [UsuarioIndicadoId], [DataIndicacao] ASC);
GO

-- Creating primary key on [ItemId] in table 'ItemAreaConhecimento'
ALTER TABLE [dbo].[ItemAreaConhecimento]
ADD CONSTRAINT [PK_ItemAreaConhecimento]
    PRIMARY KEY CLUSTERED ([ItemId] ASC);
GO

-- Creating primary key on [GrupoItemId] in table 'ItemGrupo'
ALTER TABLE [dbo].[ItemGrupo]
ADD CONSTRAINT [PK_ItemGrupo]
    PRIMARY KEY CLUSTERED ([GrupoItemId] ASC);
GO

-- Creating primary key on [ItemId] in table 'ItemSistema'
ALTER TABLE [dbo].[ItemSistema]
ADD CONSTRAINT [PK_ItemSistema]
    PRIMARY KEY CLUSTERED ([ItemId] ASC);
GO

-- Creating primary key on [LoginId] in table 'Login'
ALTER TABLE [dbo].[Login]
ADD CONSTRAINT [PK_Login]
    PRIMARY KEY CLUSTERED ([LoginId] ASC);
GO

-- Creating primary key on [LoginId], [Data] in table 'Notificacao'
ALTER TABLE [dbo].[Notificacao]
ADD CONSTRAINT [PK_Notificacao]
    PRIMARY KEY CLUSTERED ([LoginId], [Data] ASC);
GO

-- Creating primary key on [ItemId], [UsuarioId] in table 'Permissoes'
ALTER TABLE [dbo].[Permissoes]
ADD CONSTRAINT [PK_Permissoes]
    PRIMARY KEY CLUSTERED ([ItemId], [UsuarioId] ASC);
GO

-- Creating primary key on [TipoItemId] in table 'TipoItem'
ALTER TABLE [dbo].[TipoItem]
ADD CONSTRAINT [PK_TipoItem]
    PRIMARY KEY CLUSTERED ([TipoItemId] ASC);
GO

-- Creating primary key on [UsuarioId] in table 'Usuario'
ALTER TABLE [dbo].[Usuario]
ADD CONSTRAINT [PK_Usuario]
    PRIMARY KEY CLUSTERED ([UsuarioId] ASC);
GO

-- Creating primary key on [VagaId] in table 'Vaga'
ALTER TABLE [dbo].[Vaga]
ADD CONSTRAINT [PK_Vaga]
    PRIMARY KEY CLUSTERED ([VagaId] ASC);
GO

-- Creating primary key on [Cargo_CargoId], [Curriculo_CurriculoId] in table 'CargoPretendido'
ALTER TABLE [dbo].[CargoPretendido]
ADD CONSTRAINT [PK_CargoPretendido]
    PRIMARY KEY CLUSTERED ([Cargo_CargoId], [Curriculo_CurriculoId] ASC);
GO

-- Creating primary key on [Curso_CursoId], [Vaga_VagaId] in table 'FormacaoVaga'
ALTER TABLE [dbo].[FormacaoVaga]
ADD CONSTRAINT [PK_FormacaoVaga]
    PRIMARY KEY CLUSTERED ([Curso_CursoId], [Vaga_VagaId] ASC);
GO

-- Creating primary key on [ItemAreaConhecimento_ItemId], [Usuario_UsuarioId] in table 'HabilidadesUsuario'
ALTER TABLE [dbo].[HabilidadesUsuario]
ADD CONSTRAINT [PK_HabilidadesUsuario]
    PRIMARY KEY CLUSTERED ([ItemAreaConhecimento_ItemId], [Usuario_UsuarioId] ASC);
GO

-- Creating primary key on [Grupo_GrupoId], [Login_LoginId] in table 'LoginGrupo'
ALTER TABLE [dbo].[LoginGrupo]
ADD CONSTRAINT [PK_LoginGrupo]
    PRIMARY KEY CLUSTERED ([Grupo_GrupoId], [Login_LoginId] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [AreaId] in table 'Cargo'
ALTER TABLE [dbo].[Cargo]
ADD CONSTRAINT [FK_Cargo_AreaConhecimento]
    FOREIGN KEY ([AreaId])
    REFERENCES [dbo].[AreaConhecimento]
        ([AreaId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Cargo_AreaConhecimento'
CREATE INDEX [IX_FK_Cargo_AreaConhecimento]
ON [dbo].[Cargo]
    ([AreaId]);
GO

-- Creating foreign key on [AreaId] in table 'Curso'
ALTER TABLE [dbo].[Curso]
ADD CONSTRAINT [FK_Curso_AreaConhecimento]
    FOREIGN KEY ([AreaId])
    REFERENCES [dbo].[AreaConhecimento]
        ([AreaId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Curso_AreaConhecimento'
CREATE INDEX [IX_FK_Curso_AreaConhecimento]
ON [dbo].[Curso]
    ([AreaId]);
GO

-- Creating foreign key on [AreaConhecimentoId] in table 'ItemAreaConhecimento'
ALTER TABLE [dbo].[ItemAreaConhecimento]
ADD CONSTRAINT [FK_ItemAreaConhecimento_AreaConhecimento]
    FOREIGN KEY ([AreaConhecimentoId])
    REFERENCES [dbo].[AreaConhecimento]
        ([AreaId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ItemAreaConhecimento_AreaConhecimento'
CREATE INDEX [IX_FK_ItemAreaConhecimento_AreaConhecimento]
ON [dbo].[ItemAreaConhecimento]
    ([AreaConhecimentoId]);
GO

-- Creating foreign key on [CargoId] in table 'Experiencia'
ALTER TABLE [dbo].[Experiencia]
ADD CONSTRAINT [FK_Experiencia_Cargo]
    FOREIGN KEY ([CargoId])
    REFERENCES [dbo].[Cargo]
        ([CargoId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Experiencia_Cargo'
CREATE INDEX [IX_FK_Experiencia_Cargo]
ON [dbo].[Experiencia]
    ([CargoId]);
GO

-- Creating foreign key on [CargoId] in table 'Vaga'
ALTER TABLE [dbo].[Vaga]
ADD CONSTRAINT [FK_Vaga_Cargo]
    FOREIGN KEY ([CargoId])
    REFERENCES [dbo].[Cargo]
        ([CargoId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Vaga_Cargo'
CREATE INDEX [IX_FK_Vaga_Cargo]
ON [dbo].[Vaga]
    ([CargoId]);
GO

-- Creating foreign key on [CertificadoId] in table 'Certificado'
ALTER TABLE [dbo].[Certificado]
ADD CONSTRAINT [FK_Certificado_Cidade]
    FOREIGN KEY ([CertificadoId])
    REFERENCES [dbo].[Cidade]
        ([CidadeId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [CidadeId] in table 'Empresa'
ALTER TABLE [dbo].[Empresa]
ADD CONSTRAINT [FK_Empresa_Cidade]
    FOREIGN KEY ([CidadeId])
    REFERENCES [dbo].[Cidade]
        ([CidadeId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Empresa_Cidade'
CREATE INDEX [IX_FK_Empresa_Cidade]
ON [dbo].[Empresa]
    ([CidadeId]);
GO

-- Creating foreign key on [CidadeId] in table 'Endereco'
ALTER TABLE [dbo].[Endereco]
ADD CONSTRAINT [FK_Endereco_Cidade1]
    FOREIGN KEY ([CidadeId])
    REFERENCES [dbo].[Cidade]
        ([CidadeId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Endereco_Cidade1'
CREATE INDEX [IX_FK_Endereco_Cidade1]
ON [dbo].[Endereco]
    ([CidadeId]);
GO

-- Creating foreign key on [UsuarioId] in table 'Curriculo'
ALTER TABLE [dbo].[Curriculo]
ADD CONSTRAINT [FK_Curriculo_Usuario]
    FOREIGN KEY ([UsuarioId])
    REFERENCES [dbo].[Usuario]
        ([UsuarioId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Curriculo_Usuario'
CREATE INDEX [IX_FK_Curriculo_Usuario]
ON [dbo].[Curriculo]
    ([UsuarioId]);
GO

-- Creating foreign key on [CurriculoId] in table 'Experiencia'
ALTER TABLE [dbo].[Experiencia]
ADD CONSTRAINT [FK_Experiencia_Curriculo]
    FOREIGN KEY ([CurriculoId])
    REFERENCES [dbo].[Curriculo]
        ([CurriculoId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Experiencia_Curriculo'
CREATE INDEX [IX_FK_Experiencia_Curriculo]
ON [dbo].[Experiencia]
    ([CurriculoId]);
GO

-- Creating foreign key on [CursoId] in table 'Formacao'
ALTER TABLE [dbo].[Formacao]
ADD CONSTRAINT [FK_Formacao_Curso]
    FOREIGN KEY ([CursoId])
    REFERENCES [dbo].[Curso]
        ([CursoId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Formacao_Curso'
CREATE INDEX [IX_FK_Formacao_Curso]
ON [dbo].[Formacao]
    ([CursoId]);
GO

-- Creating foreign key on [UsuarioRepresentanteId] in table 'Empresa'
ALTER TABLE [dbo].[Empresa]
ADD CONSTRAINT [FK_USUARIO_REPRESENTANTE]
    FOREIGN KEY ([UsuarioRepresentanteId])
    REFERENCES [dbo].[Usuario]
        ([UsuarioId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_USUARIO_REPRESENTANTE'
CREATE INDEX [IX_FK_USUARIO_REPRESENTANTE]
ON [dbo].[Empresa]
    ([UsuarioRepresentanteId]);
GO

-- Creating foreign key on [EnderecoId] in table 'Formacao'
ALTER TABLE [dbo].[Formacao]
ADD CONSTRAINT [FK_Formacao_Formacao]
    FOREIGN KEY ([EnderecoId])
    REFERENCES [dbo].[Endereco]
        ([EnderecoId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Formacao_Formacao'
CREATE INDEX [IX_FK_Formacao_Formacao]
ON [dbo].[Formacao]
    ([EnderecoId]);
GO

-- Creating foreign key on [EnderecoId] in table 'Usuario'
ALTER TABLE [dbo].[Usuario]
ADD CONSTRAINT [FK_Usuario_Endereco]
    FOREIGN KEY ([EnderecoId])
    REFERENCES [dbo].[Endereco]
        ([EnderecoId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Usuario_Endereco'
CREATE INDEX [IX_FK_Usuario_Endereco]
ON [dbo].[Usuario]
    ([EnderecoId]);
GO

-- Creating foreign key on [UsuarioIndicadoId] in table 'Feedback'
ALTER TABLE [dbo].[Feedback]
ADD CONSTRAINT [FK_Feedback_Usuario]
    FOREIGN KEY ([UsuarioIndicadoId])
    REFERENCES [dbo].[Usuario]
        ([UsuarioId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Feedback_Usuario'
CREATE INDEX [IX_FK_Feedback_Usuario]
ON [dbo].[Feedback]
    ([UsuarioIndicadoId]);
GO

-- Creating foreign key on [UsarioPostId] in table 'Feedback'
ALTER TABLE [dbo].[Feedback]
ADD CONSTRAINT [FK_Feedback_Usuario1]
    FOREIGN KEY ([UsarioPostId])
    REFERENCES [dbo].[Usuario]
        ([UsuarioId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Feedback_Usuario1'
CREATE INDEX [IX_FK_Feedback_Usuario1]
ON [dbo].[Feedback]
    ([UsarioPostId]);
GO

-- Creating foreign key on [VagaId] in table 'Feedback'
ALTER TABLE [dbo].[Feedback]
ADD CONSTRAINT [FK_Feedback_Vaga]
    FOREIGN KEY ([VagaId])
    REFERENCES [dbo].[Vaga]
        ([VagaId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [UsuarioId] in table 'Formacao'
ALTER TABLE [dbo].[Formacao]
ADD CONSTRAINT [FK_Formacao_Usuario]
    FOREIGN KEY ([UsuarioId])
    REFERENCES [dbo].[Usuario]
        ([UsuarioId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Formacao_Usuario'
CREATE INDEX [IX_FK_Formacao_Usuario]
ON [dbo].[Formacao]
    ([UsuarioId]);
GO

-- Creating foreign key on [GrupoId] in table 'ItemGrupo'
ALTER TABLE [dbo].[ItemGrupo]
ADD CONSTRAINT [FK_ItemGrupo_Grupo]
    FOREIGN KEY ([GrupoId])
    REFERENCES [dbo].[Grupo]
        ([GrupoId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ItemGrupo_Grupo'
CREATE INDEX [IX_FK_ItemGrupo_Grupo]
ON [dbo].[ItemGrupo]
    ([GrupoId]);
GO

-- Creating foreign key on [UsuarioPublicadorId] in table 'HistoricoIndicacoes'
ALTER TABLE [dbo].[HistoricoIndicacoes]
ADD CONSTRAINT [FK_HistoricoIndicacoes_Usuario]
    FOREIGN KEY ([UsuarioPublicadorId])
    REFERENCES [dbo].[Usuario]
        ([UsuarioId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_HistoricoIndicacoes_Usuario'
CREATE INDEX [IX_FK_HistoricoIndicacoes_Usuario]
ON [dbo].[HistoricoIndicacoes]
    ([UsuarioPublicadorId]);
GO

-- Creating foreign key on [IdiomaId] in table 'IdiomaUsuario'
ALTER TABLE [dbo].[IdiomaUsuario]
ADD CONSTRAINT [FK_IdiomaUsuario_ItemAreaConhecimento]
    FOREIGN KEY ([IdiomaId])
    REFERENCES [dbo].[Idioma]
        ([IdiomaId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_IdiomaUsuario_ItemAreaConhecimento'
CREATE INDEX [IX_FK_IdiomaUsuario_ItemAreaConhecimento]
ON [dbo].[IdiomaUsuario]
    ([IdiomaId]);
GO

-- Creating foreign key on [IdiomaId] in table 'IdiomaVaga'
ALTER TABLE [dbo].[IdiomaVaga]
ADD CONSTRAINT [FK_IdiomaVaga_Idioma]
    FOREIGN KEY ([IdiomaId])
    REFERENCES [dbo].[Idioma]
        ([IdiomaId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [UsuarioId] in table 'IdiomaUsuario'
ALTER TABLE [dbo].[IdiomaUsuario]
ADD CONSTRAINT [FK_IdiomaUsuario_Usuario]
    FOREIGN KEY ([UsuarioId])
    REFERENCES [dbo].[Usuario]
        ([UsuarioId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [VagaId] in table 'IdiomaVaga'
ALTER TABLE [dbo].[IdiomaVaga]
ADD CONSTRAINT [FK_IdiomaVaga_Vaga]
    FOREIGN KEY ([VagaId])
    REFERENCES [dbo].[Vaga]
        ([VagaId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_IdiomaVaga_Vaga'
CREATE INDEX [IX_FK_IdiomaVaga_Vaga]
ON [dbo].[IdiomaVaga]
    ([VagaId]);
GO

-- Creating foreign key on [UsuarioIndicadoId] in table 'Indicacao'
ALTER TABLE [dbo].[Indicacao]
ADD CONSTRAINT [FK_Indicacao_Usuario]
    FOREIGN KEY ([UsuarioIndicadoId])
    REFERENCES [dbo].[Usuario]
        ([UsuarioId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Indicacao_Usuario'
CREATE INDEX [IX_FK_Indicacao_Usuario]
ON [dbo].[Indicacao]
    ([UsuarioIndicadoId]);
GO

-- Creating foreign key on [VagaId] in table 'Indicacao'
ALTER TABLE [dbo].[Indicacao]
ADD CONSTRAINT [FK_Indicacao_Vaga]
    FOREIGN KEY ([VagaId])
    REFERENCES [dbo].[Vaga]
        ([VagaId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [TipoItemId] in table 'ItemSistema'
ALTER TABLE [dbo].[ItemSistema]
ADD CONSTRAINT [FK_ItemSistema_TipoItem]
    FOREIGN KEY ([TipoItemId])
    REFERENCES [dbo].[TipoItem]
        ([TipoItemId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ItemSistema_TipoItem'
CREATE INDEX [IX_FK_ItemSistema_TipoItem]
ON [dbo].[ItemSistema]
    ([TipoItemId]);
GO

-- Creating foreign key on [ItemId] in table 'Permissoes'
ALTER TABLE [dbo].[Permissoes]
ADD CONSTRAINT [FK_Permissoes_ItemSistema]
    FOREIGN KEY ([ItemId])
    REFERENCES [dbo].[ItemSistema]
        ([ItemId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [LoginId] in table 'Notificacao'
ALTER TABLE [dbo].[Notificacao]
ADD CONSTRAINT [FK_Notificacao_Login]
    FOREIGN KEY ([LoginId])
    REFERENCES [dbo].[Login]
        ([LoginId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [LoginId] in table 'Usuario'
ALTER TABLE [dbo].[Usuario]
ADD CONSTRAINT [FK_Usuario_Login]
    FOREIGN KEY ([LoginId])
    REFERENCES [dbo].[Login]
        ([LoginId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Usuario_Login'
CREATE INDEX [IX_FK_Usuario_Login]
ON [dbo].[Usuario]
    ([LoginId]);
GO

-- Creating foreign key on [UsuarioId] in table 'Permissoes'
ALTER TABLE [dbo].[Permissoes]
ADD CONSTRAINT [FK_Permissoes_Usuario]
    FOREIGN KEY ([UsuarioId])
    REFERENCES [dbo].[Usuario]
        ([UsuarioId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Permissoes_Usuario'
CREATE INDEX [IX_FK_Permissoes_Usuario]
ON [dbo].[Permissoes]
    ([UsuarioId]);
GO

-- Creating foreign key on [UsuarioRepresentanteId] in table 'Vaga'
ALTER TABLE [dbo].[Vaga]
ADD CONSTRAINT [FK_Vaga_Usuario]
    FOREIGN KEY ([UsuarioRepresentanteId])
    REFERENCES [dbo].[Usuario]
        ([UsuarioId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Vaga_Usuario'
CREATE INDEX [IX_FK_Vaga_Usuario]
ON [dbo].[Vaga]
    ([UsuarioRepresentanteId]);
GO

-- Creating foreign key on [Cargo_CargoId] in table 'CargoPretendido'
ALTER TABLE [dbo].[CargoPretendido]
ADD CONSTRAINT [FK_CargoPretendido_Cargo]
    FOREIGN KEY ([Cargo_CargoId])
    REFERENCES [dbo].[Cargo]
        ([CargoId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Curriculo_CurriculoId] in table 'CargoPretendido'
ALTER TABLE [dbo].[CargoPretendido]
ADD CONSTRAINT [FK_CargoPretendido_Curriculo]
    FOREIGN KEY ([Curriculo_CurriculoId])
    REFERENCES [dbo].[Curriculo]
        ([CurriculoId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_CargoPretendido_Curriculo'
CREATE INDEX [IX_FK_CargoPretendido_Curriculo]
ON [dbo].[CargoPretendido]
    ([Curriculo_CurriculoId]);
GO

-- Creating foreign key on [Curso_CursoId] in table 'FormacaoVaga'
ALTER TABLE [dbo].[FormacaoVaga]
ADD CONSTRAINT [FK_FormacaoVaga_Curso]
    FOREIGN KEY ([Curso_CursoId])
    REFERENCES [dbo].[Curso]
        ([CursoId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Vaga_VagaId] in table 'FormacaoVaga'
ALTER TABLE [dbo].[FormacaoVaga]
ADD CONSTRAINT [FK_FormacaoVaga_Vaga]
    FOREIGN KEY ([Vaga_VagaId])
    REFERENCES [dbo].[Vaga]
        ([VagaId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_FormacaoVaga_Vaga'
CREATE INDEX [IX_FK_FormacaoVaga_Vaga]
ON [dbo].[FormacaoVaga]
    ([Vaga_VagaId]);
GO

-- Creating foreign key on [ItemAreaConhecimento_ItemId] in table 'HabilidadesUsuario'
ALTER TABLE [dbo].[HabilidadesUsuario]
ADD CONSTRAINT [FK_HabilidadesUsuario_ItemAreaConhecimento]
    FOREIGN KEY ([ItemAreaConhecimento_ItemId])
    REFERENCES [dbo].[ItemAreaConhecimento]
        ([ItemId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Usuario_UsuarioId] in table 'HabilidadesUsuario'
ALTER TABLE [dbo].[HabilidadesUsuario]
ADD CONSTRAINT [FK_HabilidadesUsuario_Usuario]
    FOREIGN KEY ([Usuario_UsuarioId])
    REFERENCES [dbo].[Usuario]
        ([UsuarioId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_HabilidadesUsuario_Usuario'
CREATE INDEX [IX_FK_HabilidadesUsuario_Usuario]
ON [dbo].[HabilidadesUsuario]
    ([Usuario_UsuarioId]);
GO

-- Creating foreign key on [Grupo_GrupoId] in table 'LoginGrupo'
ALTER TABLE [dbo].[LoginGrupo]
ADD CONSTRAINT [FK_LoginGrupo_Grupo]
    FOREIGN KEY ([Grupo_GrupoId])
    REFERENCES [dbo].[Grupo]
        ([GrupoId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Login_LoginId] in table 'LoginGrupo'
ALTER TABLE [dbo].[LoginGrupo]
ADD CONSTRAINT [FK_LoginGrupo_Login]
    FOREIGN KEY ([Login_LoginId])
    REFERENCES [dbo].[Login]
        ([LoginId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_LoginGrupo_Login'
CREATE INDEX [IX_FK_LoginGrupo_Login]
ON [dbo].[LoginGrupo]
    ([Login_LoginId]);
GO

-- Creating foreign key on [ItemId] in table 'ItemGrupo'
ALTER TABLE [dbo].[ItemGrupo]
ADD CONSTRAINT [FK_ItemGrupo_ItemSistema]
    FOREIGN KEY ([ItemId])
    REFERENCES [dbo].[ItemSistema]
        ([ItemId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ItemGrupo_ItemSistema'
CREATE INDEX [IX_FK_ItemGrupo_ItemSistema]
ON [dbo].[ItemGrupo]
    ([ItemId]);
GO

-- Creating foreign key on [UsuarioIndicadorId] in table 'Indicacao'
ALTER TABLE [dbo].[Indicacao]
ADD CONSTRAINT [FK_Indicacao_Usuario_Indicador]
    FOREIGN KEY ([UsuarioIndicadorId])
    REFERENCES [dbo].[Usuario]
        ([UsuarioId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Indicacao_Usuario_Indicador'
CREATE INDEX [IX_FK_Indicacao_Usuario_Indicador]
ON [dbo].[Indicacao]
    ([UsuarioIndicadorId]);
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------